package com.jasonzhou.onetomanycontrol.util

import android.content.Context
import android.view.Gravity
import android.widget.Toast
import com.jasonzhou.onetomanycontrol.R

class CustomToast(private val mContext: Context) {
    private val mToast: Toast = Toast.makeText(mContext, "", Toast.LENGTH_LONG)

    fun show(strCharSequence: CharSequence = "", duration: Int = Toast.LENGTH_SHORT, gravity: Int = Gravity.CENTER, x: Int = 0, y: Int = 0) {
        mToast.duration = duration
        mToast.setText(strCharSequence)
        mToast.setGravity(gravity, x, y)
        mToast.cancel()
        mToast.show()
    }

    fun show(resId: Int = R.string.app_name, duration: Int = Toast.LENGTH_SHORT, gravity: Int = Gravity.CENTER, x: Int = 0, y: Int = 0) {
        show(mContext.getText(resId), duration, gravity, x, y)
    }


    fun cancel() {
        mToast.cancel()
    }
}
